package cn.jiangjiesheng.bootstrap.commons.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * Created by dev@jiangjiesheng.cn on 2021/9/28  <br/>
 *
 * @author dev@jiangjiesheng.cn
 */
@Component
@Slf4j
public class DomainEventPublisher implements ApplicationEventPublisherAware {

    private static ApplicationEventPublisher eventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        DomainEventPublisher.eventPublisher = applicationEventPublisher;
    }

    public static <T> void publish(DomainEvent event) {
        eventPublisher.publishEvent(event);
    }
}
